package cn.iocoder.yudao.module.system.dal.mysql.productsku;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.system.dal.dataobject.productsku.ProductSkuDO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.system.controller.admin.productsku.vo.*;

/**
 * 产品规格 Mapper
 *
 * @author 数创万维
 */
@Mapper
public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> {

    default PageResult<ProductSkuDO> selectPage(ProductSkuPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProductSkuDO>()
                .eqIfPresent(ProductSkuDO::getProductId, reqVO.getProductId())
                .likeIfPresent(ProductSkuDO::getName, reqVO.getName())
                .eqIfPresent(ProductSkuDO::getNum, reqVO.getNum())
                .eqIfPresent(ProductSkuDO::getOldPrice, reqVO.getOldPrice())
                .eqIfPresent(ProductSkuDO::getPrice, reqVO.getPrice())
                .betweenIfPresent(ProductSkuDO::getExpireTime, reqVO.getExpireTime())
                .betweenIfPresent(ProductSkuDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(ProductSkuDO::getNum));
    }


    default void deleteByProductId(Long id) {
        delete(ProductSkuDO::getProductId, id);
    }
}